package com.yoake.campus.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yoake.common.annotation.Log;
import com.yoake.common.core.controller.BaseController;
import com.yoake.common.core.domain.AjaxResult;
import com.yoake.common.enums.BusinessType;
import com.yoake.campus.domain.CampusFile;
import com.yoake.campus.service.ICampusFileService;
import com.yoake.common.utils.poi.ExcelUtil;
import com.yoake.common.core.page.TableDataInfo;

/**
 * 文件管理Controller
 * 
 * @author yoake
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/campus/file")
public class CampusFileController extends BaseController
{
    @Autowired
    private ICampusFileService campusFileService;

    /**
     * 查询文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('campus:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(CampusFile campusFile)
    {
        startPage();
        List<CampusFile> list = campusFileService.selectCampusFileList(campusFile);
        return getDataTable(list);
    }


    /**
     * 获取文件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('campus:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return success(campusFileService.selectCampusFileByFileId(fileId));
    }

    /**
     * 新增文件管理
     */
    @PreAuthorize("@ss.hasPermi('campus:file:add')")
    @Log(title = "文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CampusFile campusFile)
    {
        return toAjax(campusFileService.insertCampusFile(campusFile));
    }

    /**
     * 修改文件管理
     */
    @PreAuthorize("@ss.hasPermi('campus:file:edit')")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CampusFile campusFile)
    {
        return toAjax(campusFileService.updateCampusFile(campusFile));
    }

    /**
     * 删除文件管理
     */
    @PreAuthorize("@ss.hasPermi('campus:file:remove')")
    @Log(title = "文件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(campusFileService.deleteCampusFileByFileIds(fileIds));
    }
}
